﻿using System.IO;

namespace SQLFileComparer
{
    public struct ActionParams
    {
        public bool Debug;
        public string Key;
        public uint PartSize;
    }

    public class MainAction
    {
        #region 'Constants'

        public const int COk = 0;
        public const int CDirectoryNotFound = 1;
        public const int CUnexpectdEnd = 2;
        public const int CBadData = 3;

        #endregion

        protected readonly MemoryStream DataHolder;
        protected readonly ActionParams Params;
        protected const int CrsaInSize = 100;
        protected const int CrsaOutSize = 128;

        protected void WriteBytes(byte[] bytes, bool flush = true)
        {
            if(flush)
                Flush();

            DataHolder.Write(bytes, 0, bytes.Length);
        }

        public void Flush()
        {
            DataHolder.SetLength(0);
        }

        public void LoadFromFile(string fileName)
        {
            WriteBytes(File.ReadAllBytes(fileName));
        }

        public void SaveToFile(string fileName)
        {
            using (var fileStream = new FileStream(fileName, FileMode.Create))
            {
                var bytes = DataHolder.ToArray();
                fileStream.Write(bytes, 0, bytes.Length);
            }
        }

        public MainAction(ActionParams actionParams)
        {
            DataHolder = new MemoryStream();
            Params = actionParams;
        }
    }
}
